package ca.concordia.soen6011;

import java.text.DecimalFormat;

/**
 * RESULT POJO
 * -----------------------------------------------------
 * 
 * The result POJO to hold the result after it's computed
 * 
 * @author musab.mirza
 * @since July-August 2014
 * 
 *        *****************************************************************
 *        TRANSIENT FUNCTION CALCULATOR is a team project for the SOEN 6011
 *        course delivered by Dr. Kamthan, Pankaj at Concordia University,
 *        Montreal for the summer 2014 session.
 *        *****************************************************************
 */
public class Result {

	private double output; // The output based on the precision
	private double computationTime; // Milliseconds
	private double precision;

	public double getOutput() {
		return output;
	}

	public void setOutput(double output) {
		this.output = output;
	}

	public void setPrecison(double precison) {
		this.precision = precison;
	}

	public double getPrecision() {
		return precision;
	}

	public double getComputationTime() {
		return computationTime;
	}

	public void setComputationTime(double computationTime) {
		this.computationTime = computationTime;
	}

	/**
	 * The printing function
	 */
	public String toString() {

		// finding no of decimal places in the precision
		int noOfDecimalPlaces = 0;
		double current = precision;
		while (true) {
			if ((1 - current) == 0)
				break;
			current = current * 10;
			noOfDecimalPlaces++;
		}

		return "\n==========================================="
				+ "\n-------------------------------------------"
				+ "\nOutput: "
				+ String.format("%." + noOfDecimalPlaces + "f", output)
				+ " | Computation time: " + computationTime + " ms"
				+ "\n-------------------------------------------"
				+ "\n===========================================";

	}
}
